package net.domor.pms.config;

import com.google.common.collect.Maps;
import net.domor.pms.common.utils.PropertiesLoader;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * Created by 汪国成 on 2017/3/22.
 */
public class Global {

    private static Global global = new Global();

    /**
     * 保存全局属性值
     */
    private static Map<String, String> map = Maps.newHashMap();

    private static PropertiesLoader loader = new PropertiesLoader("config.properties");

    public static Global getInstance() {
        return global;
    }

    public static String getConfig(String key) {
        String value = map.get(key);
        if (value == null) {
            value = loader.getProperty(key);
            map.put(key, value != null ? value : StringUtils.EMPTY);
        }
        return value;
    }

    public static String getAdminPath() {
        return getConfig("adminPath");
    }
}
